package com.example.client

/**
 * @Author: leali
 * @Version: 1.0
 * @Date: 9/21/2020-1:34 PM
 * @Description: 多线程并发操作
 */
object MyActor {
  def sumOfFactors(number: Int): Int = {
    (1 to number).foldLeft(0)((sum, i) => if (number % i == 0) sum + i else sum)
  }

  def isPerfect(candidate: Int): Boolean = 2 * candidate == sumOfFactors(candidate)

  //  def sumOfFactorsInRange(lower: Int, upper: Int, number: Int): Int = {
  //    (lower to upper).foldLeft((sum, i) => if (number % i == 0) sum + i else sum)
  //  }
  //  def isPerfectConcurrent(candidate:Int): Unit ={
  //    val RANGE=1000000
  //    val numberOfPartitions=(candidate.toDouble/RANGE).ceil.toInt
  //    val caller=self
  //    for(i<- 0 until  numberOfPartitions){
  //        val lower=RANGE*i+1
  //        val upper=candidate min(i+1)*RANGE
  //      actor{
  //        caller　! sumOfFactorsInRange(lower,upper,candidate)
  //      }
  //    }
  //  }
  def main(args: Array[String]): Unit = {
    println(isPerfect(6))
    println(isPerfect(33550336))
    println(isPerfect(33550337))

  }
}
